import org.junit.After;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import javax.annotation.Resources;
import java.io.IOException;
import java.io.Reader;
import java.util.List;

import static javax.annotation.Resources.*;
import static org.apache.ibatis.io.Resources.getResourceAsReader;

public class MyBatisTest<sqlSessionFactory, sqlSession> {
    private sqlSessionFactory sqlSessionFactory;
    private sqlSession sqlSession;
    @BeforeAll
    public void init () {
        String resources = "mybatis-config.xml";
        Reader reader = null;
        try{
            reader = getResourceAsReader(resources);
            sqlSessionFactory sqlMapper =new
                    sqlSessionFactoryBuilder().build(reader);
            sqlSession= sqlMapper.openSession();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    @Test
    public <Student> void findAllStudentTest(){
        List<Student> list =
                sqlSession.selectList("com.itheime.mapper.StudentMapper.findAllStudent");
        for (Student student : list) {
            System.out.println(student);
        }
    }
    @After
    public void destory() {
        sqlSession.comit();
        sqlSession.close();
    }
}
